﻿using System;
using HslCommunication.ModBus;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Inovance
{
	/// <summary>
	/// 汇川的串口通信协议，适用于H3U, XP 等系列，底层走的是MODBUS-TCP协议，地址说明参见标记<br />
	/// Huichuan's serial communication protocol is suitable for H3U, XP and other series. 
	/// The bottom layer is MODBUS-TCP protocol. For the address description, please refer to the mark
	/// </summary>
	/// <remarks>
	/// <inheritdoc cref="T:HslCommunication.Profinet.Inovance.InovanceH3UTcp" path="remarks" />
	/// </remarks>
	// Token: 0x02000095 RID: 149
	public class InovanceH3USerial : ModbusRtu
	{
		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.#ctor" />
		// Token: 0x06000B47 RID: 2887 RVA: 0x0001A8CC File Offset: 0x00018ACC
		public InovanceH3USerial()
		{
		}

		/// <summary>
		/// 指定客户端自己的站号来初始化<br />
		/// Specify the client's own station number to initialize
		/// </summary>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000B48 RID: 2888 RVA: 0x0001A8D6 File Offset: 0x00018AD6
		public InovanceH3USerial(byte station = 1) : base(station)
		{
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000B49 RID: 2889 RVA: 0x00042BB8 File Offset: 0x00040DB8
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Read(operateResult.Content, length);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000B4A RID: 2890 RVA: 0x00042BF8 File Offset: 0x00040DF8
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000B4B RID: 2891 RVA: 0x00042C38 File Offset: 0x00040E38
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 1);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.ReadBool(operateResult.Content, length);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000B4C RID: 2892 RVA: 0x00042C78 File Offset: 0x00040E78
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, values);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.Write(System.String,System.Boolean)" />
		// Token: 0x06000B4D RID: 2893 RVA: 0x00042CB8 File Offset: 0x00040EB8
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.Write(System.String,System.Int16)" />
		// Token: 0x06000B4E RID: 2894 RVA: 0x00042CF8 File Offset: 0x00040EF8
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH3UTcp.Write(System.String,System.UInt16)" />
		// Token: 0x06000B4F RID: 2895 RVA: 0x00042D38 File Offset: 0x00040F38
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH3UAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000B50 RID: 2896 RVA: 0x00042D75 File Offset: 0x00040F75
		public override string ToString()
		{
			return string.Format("InovanceH3USerial[{0}:{1}]", base.PortName, base.BaudRate);
		}
	}
}
